﻿package com.vinyl.command
{
	import com.vinyl.command.*;
	
	public class Call implements ICommand
	{
		private var o: Object;
		private var f: Function;
		private var a: Array;
		
		public function Call( o, f, ... args )
		{
			this.o = Object( o );
			
			if( typeof( f ) == 'string' ) f = o[f];
			this.f = f;
			
			if( args.length > 0 )  this.a = args
		}
		
		public static function create( o:Object, f:Function, ... args ): Call 
		{	
			var params: Array = args;
			var instance: Call = new Call( o, f, args );
			return instance;
		}
		
		public function setArguments( ... args ): void
		{
			this.a = args;
		}
		
		public function execute( ... args ): Function
		{
			if( args.length > 0 ) return f.apply( o, args );
			else return f.apply( o, a );
		}
		
		public function toString(): String
		{
			return '[Call]';
		}
	}
}